//
//  BaseHttpManager.m
//  Cycling
//
//  Created by cjg.mini on 2023/3/2.
//

#import "BaseHttpManager.h"

static BaseHttpManager *manager = nil;

@implementation BaseHttpManager

+(instancetype)defaultManager {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[BaseHttpManager alloc] init];
    });
    return manager;
}

- (instancetype)init {
    if (self = [super init]) {
        self.sessionManager = [AFHTTPSessionManager manager];
        self.sessionManager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; //不设置会报-1016或者会有编码问题
        [self configureRequestSerializer];
    }
    return self;
}

//配置请求头处理json数据类型 （请求头json数据类型、返回体多类型）
- (void)configureRequestSerializer {
    self.sessionManager.requestSerializer = [AFJSONRequestSerializer serializer]; //不设置会报-1016或者会有编码问题
    self.sessionManager.responseSerializer = [AFJSONResponseSerializer serializer]; //不设置会报 error 3840
    [self.sessionManager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];//json类型
    [self.sessionManager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", @"text/plain", @"application/x-www-form-urlencoded; charset=utf-8", @"application/vnd.geo+json", nil]];
}

//配置请求头处理json数据类型 （请求头form表单数据类型、返回体多类型）
- (void)configureRequestSerializerNew {
    self.sessionManager.requestSerializer = [AFHTTPRequestSerializer serializer]; //不设置会报-1016或者会有编码问题
    self.sessionManager.responseSerializer = [AFHTTPResponseSerializer serializer]; //不设置会报 error 3840
    [self.sessionManager.requestSerializer setValue:@"application/x-www-form-urlencoded; charset=utf-8;application/json" forHTTPHeaderField:@"Content-Type"];//form表单类型
    [self.sessionManager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", @"text/plain", @"application/x-www-form-urlencoded; charset=utf-8", @"application/vnd.geo+json", nil]];
}

@end
